<?php
	
	application::addHeaderCSS("application/template/default/dhtmlx/dhtmlxLayout/codebase/dhtmlxlayout.css");
	application::addHeaderCSS("application/template/default/dhtmlx/dhtmlxLayout/codebase/skins/dhtmlxlayout_dhx_skyblue.css");
	
	application::addHeaderJS("application/template/default/dhtmlx/dhtmlxLayout/codebase/dhtmlxcommon.js");
	application::addHeaderJS("application/template/default/dhtmlx/dhtmlxLayout/codebase/dhtmlxlayout.js");
	application::addHeaderJS("application/template/default/dhtmlx/dhtmlxLayout/codebase/dhtmlxcontainer.js");
	
	
	
	application::addHeaderCSS("application/template/default/dhtmlx/dhtmlxForm/codebase/skins/dhtmlxform_dhx_skyblue.css");
	application::addHeaderJS("application/template/default/dhtmlx/dhtmlxForm/codebase/dhtmlxform.js");
?>

<style>
		html, body {
			width: 100%;
			height: 100%;
			margin: 0px;
			padding: 0px;
			overflow: hidden;
		}
	</style>
	
<div id="parentId" style="width: 100%;height: 100%;	margin: 0px;padding: 0px; overflow: hidden;"></div>

<div id="content" style="position: relative; top: 20px; left: 20px; width: 600px; height: 400px; aborder: #B5CDE4 1px solid;">

<div style="width:250px;height:200px;">
	<div id="form_container" style="width:250px;height:150px;"></div>
	<a href="index.php?component=login&controller=login&task=create">Criar Usuário?</a>
	<a href="#">Esqueceu a senha?</a>
</div>

	
		
</div>


<script>
var dhxLayout;
function doOnLoad() {
    dhxLayout = new dhtmlXLayoutObject("parentId", "1C");
    dhxLayout.cells("a").setText("Bem Vindo");
    dhxLayout.cells("a").attachObject("content");
}
doOnLoad();
</script>


<script>
		var myForm, formData;
		function doOnLoad2() {
		        formData = [
		        			{type:"settings", position:"label-top"},
                           { type: "fieldset", name: "data", label: "Autenticação", inputWidth: "auto", list:[
								{type:"input", name: 'email', label:'Usuário'},
								{type:"password", name:"password", label:"Senha"},
								{type:"button", name:"save", value:"Autenticar"}] 
							   }
                        	]
			myForm = new dhtmlXForm("form_container", formData);
			
			//myform.dataFeed("data/form.php");//specify here the path to a file which will get change requests
			//myform.bind(mygrid);
			
			id='save';
			myForm.attachEvent("onButtonClick", function(id){

     			myForm.send("index.php?webservice=true&component=login&controller=login&task=authentication","post", function(loader, response){
  					sendActionResponse( response );
  					
  				});  					
     		
			});
			
			
			
			

		}	
		
		
		function sendActionResponse( response ){
			
			//response	=	parseInt(response);
					

			switch(response){
				case	'1':
				
					//alert('Conta de usuário criada com sucesso.');
					
					window.location.href='index.php?component=home&controller=home&task=home';

					break;
				case	'2':
				
					dhtmlx.alert({
					    title:"Alerta",
					    type:"alert-error",
					    text:"Não foi possível autenticar este usuários com as credenciais passadas. Favor tentar novamente.",
					    callback: function() {window.location.href='index.php';}
					});
				
					break;
				case	'3':
				
					break;
				default:
				
					alert('Erro ao autenticar, favor tentar novamente mais tarde.');					
			}
		}
		
		
		doOnLoad2();
</script>
